package cn.xuanxuanyuhua.crm.web.controller;

import cn.xuanxuanyuhua.crm.domain.Salary;
import cn.xuanxuanyuhua.crm.query.QueryObject;
import cn.xuanxuanyuhua.crm.query.SalaryQueryObject;
import cn.xuanxuanyuhua.crm.service.IEmployeeService;
import cn.xuanxuanyuhua.crm.service.ISalaryService;
import cn.xuanxuanyuhua.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;


    @RequestMapping("/list")
    public String list(Model m, @ModelAttribute("qo")SalaryQueryObject qo){
        if(qo.getParentId() > -1){
            qo.setParentId(qo.getParentId());
            m.addAttribute("pageInfo",salaryService.query(qo));
        }
        m.addAttribute("employeeList",employeeService.list());
        return "/salary/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Salary entity){
        salaryService.saveOrUpdate(entity);
        return new JSONResult();
    }


}
